package com.jenings.shop.controller;

import com.jenings.shop.entity.Users;
import com.jenings.shop.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"用户Users"})
@RestController
@RequestMapping("/usersApi")
public class UserController {
    @Autowired
    UserService userService;
    @ApiOperation(value = "查询全部用户")
    @RequestMapping(value = "/selectAll",method = RequestMethod.POST)
    public List<Users> selectAll(){
        List<Users> usersList = userService.selectAll();
       // System.out.println(usersList);
        return usersList;
    }
    @ApiOperation(value = "查询部分用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名称", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/selectSome" , method = RequestMethod.POST)
    public List<Users> selectSome(@RequestParam(value = "username") String username){
        List<Users> usersList = userService.selectSome(username);
        return usersList;
    }
    @ApiOperation(value = "查询用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名称", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/selectByte" , method = RequestMethod.POST)
    public Users seleceByte(@RequestParam(value = "username") String username){
        Users users = userService.selectByte(username);
        return users;
    }
    @ApiOperation(value = "修改用户信息")
    @RequestMapping(value = "/updateByte" , method = RequestMethod.POST, produces = "application/json")
    public boolean updateByte(@RequestBody Users users){
        return userService.updateByte(users);
    }
    @ApiOperation(value = "添加用户")
    @RequestMapping(value = "/insertByte" , method = RequestMethod.POST, produces = "application/json")
    public boolean insertByte(@RequestBody Users users){
        return userService.insertByte(users);
    }
    @ApiOperation(value = "删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userid", value = "用户id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/delByte" , method = RequestMethod.POST)
    public boolean delByte(@RequestParam(value = "userid") Integer userid){
        return userService.delByte(userid);
    }
}
